﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// Summary description for HienThi
/// </summary>
public class HienThi
{
    private string ConnectString = ConfigurationManager.ConnectionStrings["ConnectString"].ConnectionString;
    public SqlConnection con;
    public HienThi()
    {
        con = new SqlConnection(ConnectString);
        con.Open();	
    }
    public DataTable LAYDL(SqlCommand CMD)
    {
       CMD.Connection = con;
       SqlDataAdapter DA = new SqlDataAdapter(CMD);
       DataSet DS = new DataSet();
       DA.Fill(DS);
       return DS.Tables[0];

    }
    public int THUCTHI(SqlCommand CMD)
    {
       CMD.Connection = con;
       return CMD.ExecuteNonQuery();
    }

    public SqlDataReader ExecuteReader(SqlCommand CMD)
    {
        CMD.Connection = con;
        return CMD.ExecuteReader();
    }

    public int CheckPer(string action_name, int idgroups)
    {
        SqlCommand CMD = new SqlCommand();
        CMD.Connection = con;
        CMD.CommandType = CommandType.StoredProcedure;
        CMD.CommandText = "SP_C_Permission";
        CMD.Parameters.Add("@action_name", SqlDbType.VarChar).Value = action_name;
        CMD.Parameters.Add("@idgroups", SqlDbType.Int).Value = idgroups;
        string a=CMD.ExecuteScalar().ToString();
        return int.Parse(a);
    }

    //public string CheckUser(string username)
    //{
    //    SqlCommand CMD = new SqlCommand("select username from users where username=@username");
    //    CMD.Connection = con;
    //    CMD.Parameters.Add("@username", SqlDbType.VarChar).Value = username;
    //    string a = CMD.ExecuteScalar().ToString();
    //    return a;
    //}
}


